package com.example.demo.myqueue;

import java.util.concurrent.DelayQueue;

public class Consumer implements Runnable {

    private DelayQueue<Message> queue;

    public Consumer(DelayQueue<Message> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (queue.size() != 0) {
            System.out.println("size=" + queue.size());
            Message take = null;
            try {
                take = queue.take();
                System.out.println(take);
                System.out.println(System.currentTimeMillis());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//            System.out.println("消费消息id：" + take.getId() + " 消息体：" + take.getComment()
//            );
        }
        System.out.println("size2=" + queue.size());
    }
}
